using System;
using System.Data;
using System.Windows.Forms;
using PointOfSale.Global;
using PointOfSale.Class;

namespace PointOfSale.PointOfSale
{
	public class frmRoomDetails : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.TextBox txtRoomName;
		private System.Windows.Forms.Label label1;

		//Cac bien dung de tao ra ket noi den co so du lieu
		private System.Windows.Forms.ListView lsvRoom;
		private System.Windows.Forms.ColumnHeader clhRoom;
		private System.Windows.Forms.ColumnHeader clhChkIn;
		private System.Windows.Forms.ColumnHeader clhChkOut;

		private System.ComponentModel.Container components = null;

		public frmRoomDetails()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lsvRoom = new System.Windows.Forms.ListView();
			this.clhRoom = new System.Windows.Forms.ColumnHeader();
			this.clhChkIn = new System.Windows.Forms.ColumnHeader();
			this.clhChkOut = new System.Windows.Forms.ColumnHeader();
			this.label1 = new System.Windows.Forms.Label();
			this.txtRoomName = new System.Windows.Forms.TextBox();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.lsvRoom);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.txtRoomName);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(8, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(408, 216);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Search Room";
			// 
			// lsvRoom
			// 
			this.lsvRoom.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					  this.clhRoom,
																					  this.clhChkIn,
																					  this.clhChkOut});
			this.lsvRoom.FullRowSelect = true;
			this.lsvRoom.GridLines = true;
			this.lsvRoom.Location = new System.Drawing.Point(8, 48);
			this.lsvRoom.Name = "lsvRoom";
			this.lsvRoom.Size = new System.Drawing.Size(392, 160);
			this.lsvRoom.TabIndex = 2;
			this.lsvRoom.View = System.Windows.Forms.View.Details;
			this.lsvRoom.Click += new System.EventHandler(this.lsvRoom_Click);
			this.lsvRoom.DoubleClick += new System.EventHandler(this.lsvRoom_DoubleClick);
			// 
			// clhRoom
			// 
			this.clhRoom.Text = "Room";
			this.clhRoom.Width = 88;
			// 
			// clhChkIn
			// 
			this.clhChkIn.Text = "Check In";
			this.clhChkIn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.clhChkIn.Width = 143;
			// 
			// clhChkOut
			// 
			this.clhChkOut.Text = "Check Out";
			this.clhChkOut.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.clhChkOut.Width = 157;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "Room Name";
			// 
			// txtRoomName
			// 
			this.txtRoomName.Location = new System.Drawing.Point(80, 16);
			this.txtRoomName.Name = "txtRoomName";
			this.txtRoomName.TabIndex = 0;
			this.txtRoomName.Text = "";
			this.txtRoomName.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.txtRoomName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtRoomName_KeyDown);
			// 
			// btnOK
			// 
			this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnOK.Location = new System.Drawing.Point(200, 224);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 1;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnClose
			// 
			this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnClose.Location = new System.Drawing.Point(280, 224);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 2;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// frmRoomDetails
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(422, 252);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmRoomDetails";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = " Room Details";
			this.Load += new System.EventHandler(this.frmRoomDetails_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

//			this.groupBox1.Text = clsGlobal.g_Hashtable["SearchRoom"].ToString();
//			this.clhRoom.Text = clsGlobal.g_Hashtable["RoomName"].ToString();
//			this.clhChkIn.Text = clsGlobal.g_Hashtable["CheckIn"].ToString();
//			this.clhChkOut.Text = clsGlobal.g_Hashtable["CheckOut"].ToString();
//			this.label1.Text = clsGlobal.g_Hashtable["RoomName"].ToString();
//			this.btnOK.Text = clsGlobal.g_Hashtable["SearchRoombtnOK"].ToString();
//			this.btnClose.Text = clsGlobal.g_Hashtable["SearchRoombtnClose"].ToString();
//			this.Text = clsGlobal.g_Hashtable["RoomDetailFormName"].ToString();
		}
		#endregion

		private void frmRoomDetails_Load(object sender, System.EventArgs e)
		{
			DataTable dt = clsRoomDetail.GetAllDetail();
			int n = dt.Rows.Count;
			for(int i = 0; i < n; i ++){
				ListViewItem lsvItem = new ListViewItem(dt.Rows[i][0].ToString().Trim());
				lsvItem.SubItems.Add(dt.Rows[i][1].ToString().Trim());
				lsvItem.SubItems.Add(dt.Rows[i][2].ToString().Trim());
				lsvRoom.Items.Add(lsvItem);
			}
	}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
			clsGlobal.g_RoomNumber = "";
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			GetGuestInfo();
		}

		private void GetGuestInfo()
		{
			String roomNumber;
			roomNumber = txtRoomName.Text;
			DataTable guestList = clsRoomDetail.GetRoomDetail(roomNumber);
			if(guestList.Rows.Count > 0)
			{
				ReturnRoomInfo(roomNumber, guestList);
				this.Close();
			}
			else
			{
				txtRoomName.Text = "";
				txtRoomName.Focus();
			}
		}

		private void lsvRoom_Click(object sender, System.EventArgs e)
		{
			txtRoomName.Text = lsvRoom.FocusedItem.SubItems[0].Text.ToString().Trim();
		}

		private void lsvRoom_DoubleClick(object sender, System.EventArgs e)
		{
			String roomNumber = lsvRoom.FocusedItem.SubItems[0].Text.ToString().Trim();
			DataTable guestList = clsRoomDetail.GetRoomDetail(lsvRoom.FocusedItem.SubItems[0].Text.Trim());
			ReturnRoomInfo(roomNumber, guestList);
			this.Close();
		}

		private void ReturnRoomInfo(String roomNumber, DataTable guestList)
		{
////			Cho con tro tro den ham
////			frmPOSTransaction.Call delInstance = new frmPOSTransaction.Call(frmPOSTransaction.CallMethod);
////			Gan tham so.
////			delInstance(roomNumber, guestList);
		}

		private void txtRoomName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Enter)
			{
				GetGuestInfo();
			}
		}
	}
}
